package com.zh.test06BookS;

import java.util.ArrayList;
import java.util.Scanner;

public class Test {

    public static void main(String[] args) {
        ArrayList list = new ArrayList();

        while (true){
        System.out.println("-------hello--------");
        System.out.println("1.展示书籍");
        System.out.println("2.增加书籍");
        System.out.println("3.删除书籍");
        System.out.println("4.退出应用");

        //借助 Scanner类
        Scanner sc = new Scanner(System.in);
        //利用键盘录入序号  需要提示
        System.out.println("请输入想要执行功能的序号：");
        int choice = sc.nextInt();
        if (choice == 1){
            System.out.println("---------1.展示书籍");
            for (int i=0; i <= list.size() - 1; i++){
                Book b = (Book) (list.get(i));
                System.out.println(b.getbNo() + "----" + b.getbName() + "----" + b.getbAuthor());
            }

        }
            if (choice == 2){
                System.out.println("---------2.增加书籍");
                System.out.println("请输入编号，书名，作者");
               int bNo = sc.nextInt();
               String bName = sc.next();
               String bAuthor = sc.next();
                Book b = new Book();
                b.setbNo(bNo);
                b.setbName(bName);
                b.setbAuthor(bAuthor);
                //创建一个空集合
                list.add(b);

            }
            if (choice == 3){
                System.out.println("---------3.删除书籍");
                //录入想要删除书籍编号
                System.out.println("请输入想要删除的编号");
                int delNo = sc.nextInt();
                //下架对应书籍
                for (int i=0; i <= list.size() - 1; i++){
                    Book b = (Book) (list.get(i));
                    if (b.getbNo() == delNo){
                        list.remove(b);
                        System.out.println("删除成功");
                        break;  //
                    }
                }

            }
            if (choice == 4){
                System.out.println("---------4.退出应用");
                break;
            }
        }




        }



    }


